package stub;

import base.ArrayOfCategory;
import base.Category;
import javax.xml.rpc.JAXRPCException;
import javax.xml.namespace.QName;
import javax.microedition.xml.rpc.Operation;
import javax.microedition.xml.rpc.Type;
import javax.microedition.xml.rpc.ComplexType;
import javax.microedition.xml.rpc.Element;

public class CategoryServicesSoap_Stub implements stub.CategoryServicesSoap, javax.xml.rpc.Stub {

    private String[] _propertyNames;
    private Object[] _propertyValues;

    public CategoryServicesSoap_Stub() {
        _propertyNames = new String[]{ENDPOINT_ADDRESS_PROPERTY};
        _propertyValues = new Object[]{utils.Config.getServerAddress() + "CategoryServices.asmx"};
    }

    public void _setProperty(String name, Object value) {
        int size = _propertyNames.length;
        for (int i = 0; i < size; ++i) {
            if (_propertyNames[i].equals(name)) {
                _propertyValues[i] = value;
                return;
            }
        }
        // Need to expand our array for a new property
        String[] newPropNames = new String[size + 1];
        System.arraycopy(_propertyNames, 0, newPropNames, 0, size);
        _propertyNames = newPropNames;
        Object[] newPropValues = new Object[size + 1];
        System.arraycopy(_propertyValues, 0, newPropValues, 0, size);
        _propertyValues = newPropValues;

        _propertyNames[size] = name;
        _propertyValues[size] = value;
    }

    public Object _getProperty(String name) {
        for (int i = 0; i < _propertyNames.length; ++i) {
            if (_propertyNames[i].equals(name)) {
                return _propertyValues[i];
            }
        }
        if (ENDPOINT_ADDRESS_PROPERTY.equals(name) || USERNAME_PROPERTY.equals(name) || PASSWORD_PROPERTY.equals(name)) {
            return null;
        }
        if (SESSION_MAINTAIN_PROPERTY.equals(name)) {
            return new java.lang.Boolean(false);
        }
        throw new JAXRPCException("Stub does not recognize property: " + name);
    }

    protected void _prepOperation(Operation op) {
        for (int i = 0; i < _propertyNames.length; ++i) {
            op.setProperty(_propertyNames[i], _propertyValues[i].toString());
        }
    }

    //
    //  Begin user methods
    //
    public ArrayOfCategory getListOfCategories() throws java.rmi.RemoteException {
        // Copy the incoming values into an Object array if needed.
        Object[] inputObject = new Object[0];

        Operation op = Operation.newInstance(_qname_GetListOfCategories, _type_GetListOfCategories, _type_GetListOfCategoriesResponse);
        _prepOperation(op);
        op.setProperty(Operation.SOAPACTION_URI_PROPERTY, "http://antiobesity-project.org/GetListOfCategories");
        Object resultObj;
        try {
            resultObj = op.invoke(inputObject);
        } catch (JAXRPCException e) {
            Throwable cause = e.getLinkedCause();
            if (cause instanceof java.rmi.RemoteException) {
                throw (java.rmi.RemoteException) cause;
            }
            throw e;
        }
        ArrayOfCategory result;
        // Convert the result into the right Java type.
        // Unwrapped return value
        Object[] getListOfCategoriesResultObj = (Object[]) ((Object[]) resultObj)[0];
        if (getListOfCategoriesResultObj == null) {
            result = null;
        } else {
            result = new ArrayOfCategory();
            Category[] categoryArray;
            Object[] categoryObj = (Object[]) getListOfCategoriesResultObj[0];
            if (categoryObj == null) {
                categoryArray = null;
            } else {
                int categoryArraySize = categoryObj.length;
                categoryArray = new Category[categoryArraySize];
                for (int categoryArrayIndex = 0;
                        categoryArrayIndex < categoryArraySize;
                        ++categoryArrayIndex) {
                    if (categoryObj[categoryArrayIndex] == null) {
                        categoryArray[categoryArrayIndex] = null;
                    } else {
                        categoryArray[categoryArrayIndex] = new Category();
                        java.lang.String string;
                        Object IDObj = ((Object[]) categoryObj[categoryArrayIndex])[0];
                        string = (java.lang.String) IDObj;
                        categoryArray[categoryArrayIndex].setId(string);
                        java.lang.String string2;
                        Object nameObj = ((Object[]) categoryObj[categoryArrayIndex])[1];
                        string2 = (java.lang.String) nameObj;
                        categoryArray[categoryArrayIndex].setName(string2);
                    }
                }
            }
            result.setCategories(categoryArray);
        }
        return result;
    }

    	public Category getById(java.lang.String id) throws java.rmi.RemoteException {
		// Copy the incoming values into an Object array if needed.
		Object[] inputObject = new Object[1];
		inputObject[0] = id;

		Operation op = Operation.newInstance(_qname_GetById, _type_GetById, _type_GetByIdResponse);
		_prepOperation(op);
		op.setProperty(Operation.SOAPACTION_URI_PROPERTY, "http://antiobesity-project.org/GetById");
		Object resultObj;
		try {
			resultObj = op.invoke(inputObject);
		} catch (JAXRPCException e) {
			Throwable cause = e.getLinkedCause();
			if (cause instanceof java.rmi.RemoteException) {
				throw (java.rmi.RemoteException) cause;
			}
			throw e;
		}
		Category result;
		// Convert the result into the right Java type.
		// Unwrapped return value
		Object[] getByIdResultObj = (Object[]) ((Object[])resultObj)[0];
		if (getByIdResultObj == null) {
			result = null;
		} else {
			result = new Category();
			java.lang.String string;
			Object IDObj = getByIdResultObj[0];
			string = (java.lang.String)IDObj;
			result.setId(string);
			java.lang.String string2;
			Object nameObj = getByIdResultObj[1];
			string2 = (java.lang.String)nameObj;
			result.setName(string2);
		}
		return result;
	}

    //
    //  End user methods
    //
    protected static final QName _qname_Category = new QName("http://antiobesity-project.org/", "Category");
    protected static final QName _qname_GetById = new QName("http://antiobesity-project.org/", "GetById");
    protected static final QName _qname_GetByIdResponse = new QName("http://antiobesity-project.org/", "GetByIdResponse");
    protected static final QName _qname_GetByIdResult = new QName("http://antiobesity-project.org/", "GetByIdResult");
    protected static final QName _qname_GetListOfCategories = new QName("http://antiobesity-project.org/", "GetListOfCategories");
    protected static final QName _qname_GetListOfCategoriesResponse = new QName("http://antiobesity-project.org/", "GetListOfCategoriesResponse");
    protected static final QName _qname_GetListOfCategoriesResult = new QName("http://antiobesity-project.org/", "GetListOfCategoriesResult");
    protected static final QName _qname_ID = new QName("http://antiobesity-project.org/", "ID");
    protected static final QName _qname_Name = new QName("http://antiobesity-project.org/", "Name");
    protected static final QName _qname_id = new QName("http://antiobesity-project.org/", "id");
    protected static final Element _type_GetListOfCategories;
    protected static final Element _type_GetListOfCategoriesResponse;
    protected static final Element _type_GetById;
    protected static final Element _type_GetByIdResponse;

    static {
        // Create all of the Type's that this stub uses, once.
        ComplexType _complexType_getListOfCategories;
        _complexType_getListOfCategories = new ComplexType();
        _complexType_getListOfCategories.elements = new Element[0];
        _type_GetListOfCategories = new Element(_qname_GetListOfCategories, _complexType_getListOfCategories);
        Element _type_ID;
        _type_ID = new Element(_qname_ID, Type.STRING, 0, 1, false);
        Element _type_Name;
        _type_Name = new Element(_qname_Name, Type.STRING, 0, 1, false);
        ComplexType _complexType_category;
        _complexType_category = new ComplexType();
        _complexType_category.elements = new Element[2];
        _complexType_category.elements[0] = _type_ID;
        _complexType_category.elements[1] = _type_Name;
        Element _type_Category;
        _type_Category = new Element(_qname_Category, _complexType_category, 0, -1, true);
        ComplexType _complexType_arrayOfCategory;
        _complexType_arrayOfCategory = new ComplexType();
        _complexType_arrayOfCategory.elements = new Element[1];
        _complexType_arrayOfCategory.elements[0] = _type_Category;
        Element _type_GetListOfCategoriesResult;
        _type_GetListOfCategoriesResult = new Element(_qname_GetListOfCategoriesResult, _complexType_arrayOfCategory, 0, 1, false);
        ComplexType _complexType_getListOfCategoriesResponse;
        _complexType_getListOfCategoriesResponse = new ComplexType();
        _complexType_getListOfCategoriesResponse.elements = new Element[1];
        _complexType_getListOfCategoriesResponse.elements[0] = _type_GetListOfCategoriesResult;
        _type_GetListOfCategoriesResponse = new Element(_qname_GetListOfCategoriesResponse, _complexType_getListOfCategoriesResponse);
        Element _type_id;
        _type_id = new Element(_qname_id, Type.STRING);
        ComplexType _complexType_getById;
        _complexType_getById = new ComplexType();
        _complexType_getById.elements = new Element[1];
        _complexType_getById.elements[0] = _type_id;
        _type_GetById = new Element(_qname_GetById, _complexType_getById);
        Element _type_GetByIdResult;
        _type_GetByIdResult = new Element(_qname_GetByIdResult, _complexType_category, 0, 1, false);
        ComplexType _complexType_getByIdResponse;
        _complexType_getByIdResponse = new ComplexType();
        _complexType_getByIdResponse.elements = new Element[1];
        _complexType_getByIdResponse.elements[0] = _type_GetByIdResult;
        _type_GetByIdResponse = new Element(_qname_GetByIdResponse, _complexType_getByIdResponse);
    }
}
